% Feature Selection By Forward Selection
clc;
clearvars;
FrwdSelectDataFileName='..\CodesV15NewRunForDoubleCheck\Data\FrwdSelectData_ByMAE_All_68NN.mat';
FitDataFileName='..\CodesV15NewRunForDoubleCheck\Data\FrwdSelectData_ByMAE_FitExc_68NN.mat';
FindKDataFileName='..\CodesV15NewRunForDoubleCheck\Data\FindKData_All.mat';
All=load(FrwdSelectDataFileName);
Fit=load(FitDataFileName);
K=load(FindKDataFileName);

MaxFNum=20;%All.MaxFNum;
FNum=All.FNum;

%%
%% Plot OPtion
BasePlotFileName='Plots\Fig6_';
TextSize=12;
InFigsTextSize=10;
SavePlots=0;
%% Plot
f=figure(1);clf();
axes('Parent',f,'NextPlot','add');%create axes
% h(2).ax=axes('Parent',h(2).f,'NextPlot','add');

% subplot(2,3,1)
% MaxKIndex=length(K.KArray)-1;
MaxKIndex=32;
MeanMAE=mean(K.MAE(:,1:MaxKIndex),1);
plot(K.KArray(1:MaxKIndex),MeanMAE,'linewidth',2)
set(gca,'FontSize',TextSize)
set(gca,'Position',[0.13,0.17,0.78,0.75])
% errorbar(KArray,mean(MSE,1),mean(STD,1))
xlim([K.KArray(1),K.KArray(MaxKIndex+1)])
xlabel('\it k');
ylabel('Mean Absolute Error');
% ylim([0.148,0.23])
% title({'Mean Absolute Error of extracted ''w''' ,'By KNN Regression','all features included'})
[MinMeanMAE,Index]=min(MeanMAE);
% hold on
% plot([K.KArray(Index);K.KArray(Index)*0.8],[MinMeanMAE;MinMeanMAE*1.1],':k','linewidth',2)
% text(K.KArray(Index)*0.8,MinMeanMAE*1.2,{['      ','\it k',' = ',num2str(K.KArray(Index))],['MAE = ',num2str(MinMeanMAE,'%0.4f')]},'FontSize',14,'horizontalalignment','center')
% hold off

% set(gca,'XTick',1:2:15)
text(-3,0.3,'A)','FontSize',TextSize,'FontWeight','Bold')

% subplot(2,3,4)
% MeanMAE=mean(K.MAE(:,1:MaxKIndex),1);
% plot(K.KArray(1:MaxKIndex),MeanMAE,'linewidth',2)
% set(gca,'FontSize',TextSize)
% % errorbar(KArray,mean(MSE,1),mean(STD,1))
% xlim([K.KArray(1),K.KArray(MaxKIndex+1)])
% ylim([MinMeanMAE-1e-4,MinMeanMAE+1e-3])
% xlabel('K');
% ylabel('Mean Absolute Error');
% 
% 
% set(gca,'XTick',20:20:140)
% text(-40,0.1113,'B)','FontSize',TextSize,'FontWeight','Bold')

% set(gca,'FontSize',TextSize)

axes('Parent',f,'NextPlot','add');%create axes
set(gca,'FontSize',TextSize);
% set(gca,'Position',[0.41,0.15,0.4875,0.4])
set(gca,'Position',[0.424,0.17,0.486,0.75])
set(gca,'Box',true)
plot(K.KArray(12:MaxKIndex),MeanMAE(12:end),'linewidth',2)
xlim([K.KArray(12),K.KArray(MaxKIndex+1)])
ylim([0.1843,0.1850])
[MinMeanMAE,Index]=min(MeanMAE);
hold on
plot([K.KArray(Index);K.KArray(Index)*0.8],[MinMeanMAE;MinMeanMAE+3*1e-4],':k','linewidth',2)
text(K.KArray(Index)*0.8,MinMeanMAE+5*1e-4,{['\itk',' = ',num2str(K.KArray(Index))],['MAE = ',num2str(MinMeanMAE,'%0.4f')]},'FontSize',14,'horizontalalignment','center')
hold off

set(gcf,'Position',[10,50,800,300])
if SavePlots
FileName=[BasePlotFileName,'A'];
saveas(gcf,[FileName,'.jpg']);
saveas(gcf,[FileName,'.emf']);
end
